package com.hq.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hq.zb.mapper.CodeLineMapper;
import com.hq.zb.model.CodeLine;
import com.hq.zb.service.ICodeLineService;
import com.hq.zb.utils.RedisUtil;
import com.hq.zb.vo.CodeLineVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 数据字典行表 服务实现类
 * </p>
 *
 * @author huanghanrui
 * @since 2022-03-09
 */
@Service
public class CodeLineServiceImpl extends ServiceImpl<CodeLineMapper, CodeLine> implements ICodeLineService {

    @Autowired
    private CodeLineMapper codeLineMapper;

    @Override
    public List<CodeLineVo> queryByCode(String code) {
        //先查缓存
        List<CodeLineVo> codeLineDtos = RedisUtil.getListBean(code, CodeLineVo.class);
        if (CollectionUtil.isEmpty(codeLineDtos)) {
            codeLineDtos = codeLineMapper.selectCodeLineByCode(code);
            if (CollectionUtil.isNotEmpty(codeLineDtos)) {
                RedisUtil.setListBean(code, codeLineDtos);
            }
        }
        return codeLineDtos;
    }

    @Override
    public Page<CodeLineVo> queryCode(Page<CodeLineVo> page, Wrapper<CodeLineVo> wrapper) {
        page.setRecords(codeLineMapper.queryCode(page, wrapper));
        return page;
    }
}
